package sunil.spring.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sunil.spring.form.Contact;

@Repository
public class ContactDAOImpl implements ContactDAO{
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public void addConatct(Contact contact){
		sessionFactory.getCurrentSession().save(contact);
		
	}
	
	  public List<Contact> listContact() {
		  
	        return sessionFactory.getCurrentSession().createQuery("from Contact").list();
	    }
	 
	    public void removeContact(Integer id) {
	        Contact contact = (Contact) sessionFactory.getCurrentSession().load(Contact.class, id);
	        if (null != contact) {
	            sessionFactory.getCurrentSession().delete(contact);
	        }
	 
	    }

		@Override
		public void addContact(Contact contact) {
			// TODO Auto-generated method stub
			
		}
	
	

}
